package com.csxy.systemmanager.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.csxy.systemmanager.common.ResponseResult;
import com.csxy.systemmanager.entity.Order;
import com.csxy.systemmanager.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@CrossOrigin//允许跨域
public class OrderController {
    @Autowired
    OrderService orderService;
    

//    @GetMapping("/orderList")
//    public ResponseResult getOrderList()
//    {
//        ResponseResult responseResult = orderService.selectAllOrderList();
//        return  new ResponseResult<>(200,"查询成功",responseResult);
//    }
    @GetMapping("/orderList")
    public ResponseResult getOrderListByPage(Integer current, Integer size, Order order){
        //调用service
        IPage<Order> page = orderService.getOrderListByPage(current,size,order);
        return  new ResponseResult<>(200,"查询成功",page);
    }



    @PostMapping("/insertOrder")
    public ResponseResult insertOrder(@RequestBody Order order)
    {
        ResponseResult responseResult = orderService.insertOrders(order);
        return  new ResponseResult<>(200,"插入成功",responseResult);
    }

    @PutMapping("/updateOrder")
    public ResponseResult updateOrder(@RequestBody Order order)
    {
        ResponseResult responseResult = orderService.updateOrdersById(order);
        System.out.println(order);
        return  new ResponseResult<>(200,"更新成功",responseResult);

    }

    @GetMapping("/searchOrder")
    public ResponseResult searchOrder(Order order)
    {
        ResponseResult responseResult = orderService.searchOrdersByShopName(order);
        return  new ResponseResult<>(200,"查询成功",responseResult);
    }

    @DeleteMapping("/deleteOrder")
    public ResponseResult deleteOrder(Integer orderId)
    {
        ResponseResult responseResult = orderService.deleteOrdersById(orderId);
        return  new ResponseResult<>(200,"删除成功",responseResult);
    }




}
